/*****************************************************************
 Naicigam Engine v0.1

 File: Timer.cpp
 Created: 22/04/08
*****************************************************************/

//-------------------------------------------------------------
#include "Timer.h"
//----------------------------------------------------------------
using namespace leo;
//-----------------------------------------------------------------------------
Timer::Timer ()
:
TimeBetweenFrames(0),
MeasureFpsSample(0),
FPS(0),
FrameCounter(0)
{
	/***/
}
//-----------------------------------------------------------------------------
Timer::~Timer ()
{
	/***/
}
//-----------------------------------------------------------------------------
void Timer::firstMeasure()
{
	QueryPerformanceFrequency(&Frequency);
	QueryPerformanceCounter(&PerfCount1);

	TimeBetweenFrames = 0;
	MeasureFpsSample = 0;
	FPS = 0;
	FrameCounter = 0;
}
//-----------------------------------------------------------------------------
void Timer::measure()
{
	QueryPerformanceCounter(&PerfCount2);
	
	TimeBetweenFrames = static_cast<double>
		((PerfCount2.QuadPart - PerfCount1.QuadPart) *1000.0f / Frequency.QuadPart);
	
	MeasureFpsSample += TimeBetweenFrames;

	FrameCounter++;
	PerfCount1 = PerfCount2;
	
	if(MeasureFpsSample >= 1000)
	{
		MeasureFpsSample -= 1000;
		FPS = FrameCounter;
		FrameCounter = 0;
	}
}
//-----------------------------------------------------------------------------